package org.wevil.controller.sys;




import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wevil.params.add.RoleAP;
import org.wevil.params.delete.DeleteParam;
import org.wevil.params.page.RolePP;
import org.wevil.params.update.RoleMenuUP;
import org.wevil.params.update.RoleOrgUP;
import org.wevil.params.update.RoleUP;
import org.wevil.service.sys.RoleService;
import org.wevil.util.page.PageResult;
import org.wevil.vo.Result;
import org.wevil.vo.list.MenuListVo;
import org.wevil.vo.list.OrgListVo;
import org.wevil.vo.list.RoleListVo;

import javax.annotation.Resource;
import java.util.List;

@Validated
/** 角色管理 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Resource
    RoleService roleService;

    /** 获取角色列表信息 */
    @PostMapping("/page")
    public Result<PageResult<RoleListVo>> getSysRoleList(
            @RequestBody @Validated RolePP param
    ) {
        PageResult<RoleListVo> data = roleService.page(param);
        return Result.success(data);
    }

    /** 新增角色 */
    @PostMapping("/add")
    public Result<String> add(
            @RequestBody @Validated RoleAP param
    ) {
        roleService.add(param);
        return Result.success();
    }

    /** 删除角色 */
    @DeleteMapping("/delete")
    public Result<String> delRole(
             @RequestBody DeleteParam param
    ) {
        roleService.del(param);
        return Result.success();
    }

    /** 修改角色 */
    @PutMapping("/update")
    public Result<String> updateRole(
            @RequestBody @Validated RoleUP param
    ) {
        roleService.update(param);
        return Result.success();
    }

    // -----------------------------------------------------角色-组织-----------------------------------------------//

    /** 查询角色所属组织 */
    @GetMapping("/getOrg")
    public Result<OrgListVo> getRole(
             @RequestParam Integer roleId
    ) {
        OrgListVo data = roleService.getOrg(roleId);
        return Result.success(data);
    }

    /** 角色修改所属组织 */
    @PutMapping("/updateOrg")
    public Result<String> addRoleMenu(
            @RequestBody @Validated RoleOrgUP param
    ) {
        roleService.updateRoleOrg(param);
        return Result.success();
    }

    // -----------------------------------------------------角色-菜单-----------------------------------------------//

    /** 查询角色相应菜单 */
    @GetMapping("/getMenu")
    public Result<List<MenuListVo>> getMenu(
             @RequestParam Integer roleId
    ) {
        List<MenuListVo> data = roleService.getMenu(roleId);
        return Result.success(data);
    }

    /** 角色修改相应菜单 */
    @PutMapping("/updateMenu")
    public Result<String> updateMenu(
            @RequestBody @Validated RoleMenuUP param
    ) {
        roleService.updateRoleMenu(param);
        return Result.success();
    }

    // -----------------------------------------------------角色-栏目-----------------------------------------------//

//    /** 角色修改相应栏目权限 */
//    @PutMapping("/putRoleSubject")
//    public ResponseUtil<String> putRoleSubject(
//            @RequestBody @Validated RolePutSubjectUP rolePutSubjectUP
//    ) {
//        Integer roleId = rolePutSubjectUP.getRoleId();
//        List<Integer> subjectIds = rolePutSubjectUP.getSubjectIds();
//        roleService.updateRoleSubject(roleId, subjectIds);
//        return ResponseUtil.info(HTTPEnum.SUCCESS);
//    }

//
//    /** 角色查询相应栏目权限 */
//    @PostMapping("/getMenuBySubjectId")
//    public ResponseUtil<List<Integer>> getMenuBySubjectId(
//             @RequestParam Integer roleId
//    ) {
//        List<Integer> data = roleService.getSubjectIdsByRoleId(roleId);
//        return ResponseUtil.info(HTTPEnum.SUCCESS, data);
//    }
}
